﻿////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// <copyright>Copyright 2008-2011 Andreas Huber Doenni</copyright>
// Distributed under the GNU General Public License version 2 (GPLv2).
// See accompanying file License.txt or copy at http://phuse.codeplex.com/license.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

namespace Phuse.Mime
{
    /// <summary>Processes a body part of a multipart entity.</summary>
    internal sealed class BodyPartProcessor : EntityProcessor<BodyPart>
    {
        private readonly bool parentIsDigest;

        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        internal BodyPartProcessor(bool parentIsDigest)
        {
            this.parentIsDigest = parentIsDigest;
        }

        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>See <see cref="EntityProcessor{T}.CreateDefaultBodyProcessor"/>.</summary>
        protected sealed override ILineProcessor<Body> CreateDefaultBodyProcessor(
            EncodingTransformation encodingTransformation, Disposition disposition)
        {
            // The absence of a content type must be interpreted as "text/plain; charset=us-ascii" or
            // "message/rfc822", see http://www.ietf.org/rfc/rfc2046.txt, 5.1./2 and 5.1.5./1.
            return this.parentIsDigest ?
                (ILineProcessor<Body>)new MessageBodyProcessor(MessageSubtypeNames.Rfc822, disposition) :
                base.CreateDefaultBodyProcessor(encodingTransformation, disposition);
        }
    }
}
